package com.beeway.blackgoose.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import com.beeway.blackgoose.MainActivity;
import com.beeway.blackgoose.R;
import com.beeway.blackgoose.adapter.GuidePagerAdapter;

import java.util.ArrayList;

/**
 * 功能介绍界面
 */
public class GuideActivity extends AppCompatActivity implements View.OnClickListener, ViewPager.OnPageChangeListener {
    private ViewPager viewPager;
    private ArrayList<View> views = new ArrayList<>();
    private GuidePagerAdapter adapter;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_guide);
        initView();
    }

    /**
     * 初始化控件
     */
    private void initView() {
        viewPager = (ViewPager) findViewById(R.id.guide_viewpager);
        for (int i = 0; i < 4; i++) {
            View view = getLayoutInflater().inflate(R.layout.guide_item_layout, null);
            ImageView img = (ImageView) view.findViewById(R.id.igv_guide_welcome);
            if (i == 0) {
                img.setImageResource(R.mipmap.viewpager_1);
            } else if (i == 1) {
                img.setImageResource(R.mipmap.viewpager_2);
            } else if (i == 2) {
                img.setImageResource(R.mipmap.viewpager_3);
            } else if (i == 3) {
                img.setImageResource(R.mipmap.viewpager_4);
                Button startBtn = (Button) view.findViewById(R.id.btn_gudie_enter);
                startBtn.setVisibility(View.VISIBLE);
                startBtn.setOnClickListener(this);
            }
            views.add(view);
        }
        adapter = new GuidePagerAdapter(views);
        viewPager.setAdapter(adapter);
        viewPager.addOnPageChangeListener(this);
    }

    @Override
    public void onClick(View v) {
        startActivity(new Intent(this, MainActivity.class));
        this.finish();
    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
    }

    @Override
    public void onPageSelected(int position) {
    }

    @Override
    public void onPageScrollStateChanged(int state) {
    }

    @Override
    public void onBackPressed() {

    }
}
